package com.uxwine.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;

public abstract class UXSettings {
	
	private Context mCtx;
	public UXSettings(Context ctx)
	{
		mCtx = ctx;
	}
	
	public abstract String getName();
	
	public void setOnChangedListener(OnSharedPreferenceChangeListener l)
	{
		SharedPreferences spf = mCtx.getSharedPreferences(getName(), 0);
		spf.registerOnSharedPreferenceChangeListener(l);
	}
	
	public void set(String key, String value)
	{
		editor(mCtx).putString(key, value).commit();
	}
	
	public void set(String key, int value)
	{
		editor(mCtx).putInt(key, value).commit();
	}
	
	public void set(String key, long value)
	{
		editor(mCtx).putLong(key, value).commit();
	}
	
	public void set(String key, boolean value)
	{
		editor(mCtx).putBoolean(key, value).commit();
	}
	
	public int getInt(String key, int defValue)
	{
		SharedPreferences spf = mCtx.getSharedPreferences(getName(), 0);
		return spf.getInt(key, defValue);
	}
	
	public String getString(String key, String defValue)
	{
		SharedPreferences spf = mCtx.getSharedPreferences(getName(), 0);
		return spf.getString(key, defValue);
	}
	
	public long getLong(String key, long defValue)
	{
		SharedPreferences spf = mCtx.getSharedPreferences(getName(), 0);
		return spf.getLong(key, defValue);
	}
	
	public boolean getBoolean(String key, boolean defValue)
	{
		SharedPreferences spf = mCtx.getSharedPreferences(getName(), 0);
		return spf.getBoolean(key, defValue);
	}
	
	private SharedPreferences.Editor editor(Context ctx)
	{
		SharedPreferences spf = ctx.getSharedPreferences(getName(), 0);
		return spf.edit();
	}
}
